package com.ruoyi.community.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.domain.IntSet;
import com.ruoyi.community.mapper.IntSetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.IntApplyMapper;
import com.ruoyi.community.domain.IntApply;
import com.ruoyi.community.service.IIntApplyService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 修改设置申请Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-23
 */
@Service
public class IntApplyServiceImpl implements IIntApplyService 
{
    @Autowired
    private IntApplyMapper intApplyMapper;

    @Autowired
    private IntSetMapper setMapper;

    /**
     * 查询修改设置申请
     * 
     * @param id 修改设置申请ID
     * @return 修改设置申请
     */
    @Override
    public IntApply selectIntApplyById(Long id)
    {
        return intApplyMapper.selectIntApplyById(id);
    }

    /**
     * 查询修改设置申请列表
     * 
     * @param intApply 修改设置申请
     * @return 修改设置申请
     */
    @Override
    public List<IntApply> selectIntApplyList(IntApply intApply)
    {
        intApply.setCommunityId(SecurityUtils.getCommunityId());
        return intApplyMapper.selectIntApplyList(intApply);
    }

    /**
     * 新增修改设置申请
     * 
     * @param intApply 修改设置申请
     * @return 结果
     */
    @Override
    public int insertIntApply(IntApply intApply)
    {
        return intApplyMapper.insertIntApply(intApply);
    }

    /**
     * 修改修改设置申请
     * 
     * @param intApply 修改设置申请
     * @return 结果
     */
    @Override
    public int updateIntApply(IntApply intApply)
    {
        return intApplyMapper.updateIntApply(intApply);
    }

    /**
     * 批量删除修改设置申请
     * 
     * @param ids 需要删除的修改设置申请ID
     * @return 结果
     */
    @Override
    public int deleteIntApplyByIds(Long[] ids)
    {
        return intApplyMapper.deleteIntApplyByIds(ids);
    }

    /**
     * 删除修改设置申请信息
     * 
     * @param id 修改设置申请ID
     * @return 结果
     */
    @Override
    public int deleteIntApplyById(Long id)
    {
        return intApplyMapper.deleteIntApplyById(id);
    }

    @Override
    @Transactional
    public int agreeApply(IntApply apply) {
        // 先更改 apply
        IntApply updateApply = new IntApply();
        updateApply.setId(apply.getId());
        updateApply.setCheckerId(SecurityUtils.getUserID());
        updateApply.setManagement(1);
        updateApply.setDelFlag("2");
        intApplyMapper.updateIntApply(updateApply);
        // 在更改 intSet
        IntSet set = new IntSet();
        set.setId(apply.getSetId());
        set.setPrice(apply.getExpectVal());
        set.setEnable(apply.getExpectEnable());
        return setMapper.updateIntSet(set);
    }
}
